package com.woniuxy.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.*;
import com.woniuxy.service.ProjectsService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (Projects)表控制层
 *
 * @author makejava
 * @since 2021-05-15 14:52:38
 */
@RestController
@RequestMapping("projects")
public class ProjectsController {
    /**
     * 服务对象
     */
    @Resource
    private ProjectsService projectsService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Projects selectOne(Integer id) {
        return this.projectsService.queryById(id);
    }

    /**
     * Description : 查询所有对象  <br/>
     * ChangeLog : 1. 创建 ( 21:26 [Hello Mr. Guo]);
     * @param
     * @return list
     */
    @GetMapping("select")
    public List<Projects> selectt(){
        List<Projects> selects = this.projectsService.selects();
        return selects;
    }



    /**
     * Description : 查询所有对象  <br/>
     * ChangeLog : 1. 创建 ( 21:26 [Hello Mr. Guo]);
     * @param
     * @return list
    */
    @GetMapping("selectAll")
    public PageInfo<Projects> selectAll(int startpage, int pagesize){

        System.out.println("汉化测试"+this.projectsService.selectAll());
        PageHelper.startPage(startpage,pagesize);
        Page<Projects> page = (Page<Projects>) this.projectsService.selectAll();
        PageInfo<Projects> projectsPageInfo = new PageInfo<>(page);
        return projectsPageInfo;
    }

    @PostMapping("search")
    public PageInfo<Projects> search(@RequestBody ProjectsDto projectsDto){
        System.out.println("qindaunhuoqude dui xiang " + projectsDto.toString());
        PageHelper.startPage(projectsDto.getPage(),projectsDto.getLimit());
        Page<Projects> page = (Page<Projects>) this.projectsService.queryAll(projectsDto.getProjectmanage());
        System.out.println("shu ju ku fan hui d shu zhi" + this.projectsService.queryAll(projectsDto.getProjectmanage()));
        PageInfo<Projects> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    @PostMapping("insert")
    public String insert(@RequestBody Projects projects){
        int insert = this.projectsService.insert(projects);
        if (insert > 0){
            return "success";
        }
        return "failure";
    }

    @PostMapping("delete/{prjId}")
    public String delete(@PathVariable("prjId") int prjId){
        boolean b = this.projectsService.deleteById(prjId);
        if (b){
            return "success";
        }
        return "failure";
    }

    @PostMapping("update")
    public String update(@RequestBody Projects projects){
        int i = this.projectsService.update(projects);
        if (i > 0){
            return "success";
        }
        return "failure";
    }
    
    /**
     * Description : 传给前端项目类型  <br/>
     * ChangeLog : 1. 创建 (2021/5/24 15:54 );
     * @return 项目类型对象
    */
    @GetMapping("selectProjects")
    @ApiOperation("获取项目数据类型")
    public ResponseEntity<Projects> selectProject(){
        List<Projects> projects = this.projectsService.selectAll();
        if (projects!=null){
            return new ResponseEntity(1,"查询项目类型成功",projects);
        }
        return new ResponseEntity(0,"查询项目类型失败");
    }

}
